package com.egu.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.NoticeInfo;
import com.egu.service.NoticeInfoService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("noticeInfo")
public class NoticeInfoController {

	@Autowired
	private NoticeInfoService noticeInfoService;

	@RequestMapping("listUI")
	public String listUI() {
		return "noticeInfo/listUI";
	}

	@RequestMapping("/getList")

	@ResponseBody
	public RequestPageVo<NoticeInfo> getList(@ModelAttribute(value = "param") PageParam param, NoticeInfo noticeInfo) {
		RequestPageVo<NoticeInfo> vo = noticeInfoService.getList(param, noticeInfo);
		return vo;
	}

	@RequestMapping("/saveOrUpdate")

	@ResponseBody
	public RequestResultVo<NoticeInfo> saveOrUpdate(NoticeInfo noticeInfo) {
		RequestResultVo<NoticeInfo> result = new RequestResultVo<NoticeInfo>();
		if (noticeInfo != null) {
			return noticeInfoService.saveOrUpdate(noticeInfo);
		} else {
			result.setSuccess(false);
		}
		return result;
	}

	@RequestMapping("/deleteDataById")
	@Transactional
	public @ResponseBody RequestResultVo<NoticeInfo> deleteDataById(
			@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<NoticeInfo> result = new RequestResultVo<NoticeInfo>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("数据库操作异常");
			return result;
		}
		result = noticeInfoService.deleteDataById(id);
		return result;
	}

}
